Attribute VB_Name = "basUtils"
'*---------------------------------------------------------------
'*
'* ModuleName:     basUtils
'* FileName:       UTILS.BAS
'* Date:           July 1998
'* Author:         Ian M. Weatherburn
'* Company:        Mindkey Software Solutions (Pty) Ltd.
'* Copyright:      Copyright (C) 1998 by Mindkey Software Solutions
'*                 All Rights Reserved
'* Description:    General Purpose Utility Routines
'*---------------------------------------------------------------

Option Explicit

Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Declare Function SetWindowPos Lib "user32" ( _
  ByVal hWnd As Long, _
  ByVal hWndInsertAfter As Long, _
  ByVal x As Long, ByVal y As Long, _
  ByVal cx As Long, ByVal cy As Long, _
  ByVal wFlags As Long) As Long

'*---------------------------------------------------------------
'* Public Variables
'*---------------------------------------------------------------
Public lngWindowVersion As Long
Public objCommandLine As clsCommandLine
Public objFileList As clsFileList
Public objBranches As clsBranches
Public objCABFile As clsCompress
Public objRASEngine As clsRASEngine

Public blnCancelConnection As Boolean


'*---------------------------------------------------------------
'* Public Constants
'*---------------------------------------------------------------

Public Const APINULL = 0&

' Version Information
Public Const VER_PLATFORM_WIN32s = 0&
Public Const VER_PLATFORM_WIN32_WINDOWS = 1&
Public Const VER_PLATFORM_WIN32_NT = 2&

Public Type OSVersionInfo  ' WIN 32 Version Info
  dwOSVersionInfoSize  As Long
  dwMajorVersion       As Long
  dwMinorVersion       As Long
  dwBuildNumber        As Long
  dwPlatformId         As Long
  szCSDVersion         As String * 128  ' Maintenance string for PSS usage
End Type

'*---------------------------------------------------------------
'* WIN32 DLL Function Declarations
'*---------------------------------------------------------------
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
  hpvDest As Any, _
  hpvSource As Any, _
  ByVal cbCopy As Long)
  
Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" ( _
  lpString1 As Any, _
  ByVal lpString2 As String _
) As Long

Public Declare Function lstrcpyn Lib "kernel32" Alias "lstrcpynA" ( _
  ByVal lpString1 As String, _
  ByVal lpString2 As String, _
  ByVal iMaxLength As Long _
) As Long

Public Declare Function FreeLibrary Lib "kernel32" ( _
  ByVal hLibModule As Long _
) As Long

Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" ( _
  ByVal lpLibFileName As String _
) As Long

Public Declare Function GetLastError Lib "kernel32" () As Long

Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" ( _
  lpVersionInformation As OSVersionInfo _
) As Long

'*---------------------------------------------------------------
'* Subroutine:  SplitPath
'* Inputs:      strPathName - Drive, folder and file specification
'* Outputs:     strDrive - Drive specified above, or
'*                         current drive if none specified
'*              strPath - Path specified above, or
'*                        current path if none specified
'*              strFileName - File mask specified above,
'*                            *.* if none specified
'*---------------------------------------------------------------
Public Sub SplitPath(ByVal strPathName As String, _
                     ByRef strDrive As String, _
                     ByRef strPath As String, _
                     ByRef strFileName As String)
                              
  Dim strNewPath As String
  Dim lngDrivePos As Long
  Dim intLength, intPos As Integer
  
  strNewPath = strPathName
  
  ' Get the Drive name
  lngDrivePos = InStr(strNewPath, ":")
  If lngDrivePos <> 0 Then
    strDrive = Left(strNewPath, lngDrivePos)
    strNewPath = Right(strNewPath, Len(strNewPath) - 2)
  Else
    strDrive = Left(CurDir, 2)
  End If
  
  ' Split the folder and file mask components
  intLength = Len(strNewPath)
  intPos = intLength
  ' Get the position of the last backslash
  Do While Mid(strNewPath, intPos, 1) <> "\"
    intPos = intPos - 1
    If intPos = 0 Then Exit Do
  Loop
  
  ' Get the filename mask
  If intPos > 0 Then
    strFileName = Mid(strNewPath, intPos + 1)
  Else
    strFileName = strNewPath
  End If
  If strFileName = "" Then strFileName = "*.*"
  
  ' Get the folder name
  If intPos > 0 Then
    strPath = Mid(strNewPath, 1, intPos)
  Else
    strPath = CurDir(strDrive) & "\"
  End If
                              
End Sub

Public Function GetTempDir() As String

  Dim strTempDir As String
  
  strTempDir = Environ("TEMP")

  If strTempDir = "" Then
    strTempDir = Environ("TMP")
    If strTempDir = "" Then
      strTempDir = CurDir
      If strTempDir = "" Then
        strTempDir = Environ("WINDIR")
          If strTempDir = "" Then
            strTempDir = "C:"
          End If ' C:\
      End If 'Windows Directory
    End If 'Current Working Directory
  End If ' TMP
  
  GetTempDir = strTempDir & "\"

End Function

'*---------------------------------------------------------------
'* Function:    fnTrimNulls
'* Input:       A string with nulls in it
'* Output:      A string with nulls removed
'* Description: Get rid of the NULLS that StrConv leaves on 95
'*---------------------------------------------------------------
Public Function fnTrimNulls(ByVal strFullOfNulls As String) As String
  If (InStr(strFullOfNulls, Chr$(0))) Then
    fnTrimNulls = Left$(strFullOfNulls, InStr(strFullOfNulls, Chr$(0)) - 1)
  End If
End Function

Public Sub CreateLongDir(strPath As String)
  Dim strDrive As String
  Dim strFolder As String
  Dim strFile As String
  Dim strBuild As String
  
  SplitPath strPath, strDrive, strFolder, strFile
  
  While InStr(2, strFolder, "\") > 1
    strBuild = strBuild & Left$(strFolder, _
               InStr(2, strFolder, "\") - 1)
    strFolder = Mid$(strFolder, InStr(2, strFolder, "\"))
    If Dir$(strDrive & strBuild, 16) = "" Then
      MkDir strDrive & strBuild
    End If
  Wend
End Sub
